<?php
   
    include 'config.php';
        $con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die("Could not execute query");
        $query = "SELECT source FROM d3 WHERE userid = 1";
        $result = mysqli_query($con, $query) or die("Could not get * FROM d3");
        $array = mysqli_fetch_all($result);
        $num = mysqli_num_rows($result);
        // echo "number of rows = "; 
       // print_r($num);
        //echo "<br/>";
        //echo ' { "name":"1", "children": [';
        
      while ($num = mysqli_fetch_array($result))
    {
    $source  = json_encode($num['source']);
    $id = json_encode($num['id']);
	$type = json_encode($num['type']);
	$context= json_encode($num['context']);
	$title = json_encode($num['title']);

 }; 
	
	
	$arrlength = count($result);
                             for($x=0;$x<$arrlength;$x++) {
                     $source  = json_encode($num['source']);
				
 $array2 = array(
     "name" => "example",    
	   "children" => array(
	      array(
	       "name" => "group1", 
	        "children" => array(
		    array(
		     "name" =>   $source ,
		      "size"=>  1000
		        ),
		    array(
		    "name" =>   $source , 
		     "size"=>  2000
		        ),
		      array(
		    "name" => $source ,
		     "size"=>  3000 
		     	   ), 
	),     
), 
array(
      "name" =>'node4', 
	"size"=>  4000,	

),
    array(
      "name" =>'node5', 
	"size"=>  5000,
),
),
);

echo json_encode($array2);
	  }

header("content-type:application/json");
    
?>
